<?php

/**
 * Homepage presenter.
 */
class ProductsPresenter extends BasePresenter
{
    public function renderList($productCategory)
    {
        $this->template->dph = 1.21;
        
        $this->template->registerHelper('price', function($s) {
            if (abs($s - floor($s)) < 0.001)
            {
                return number_format(round($s), 0, ',', ' ');
            }
            else
            {
                return number_format(round($s, 2), 2, ',', ' ');
            }
            
        });
        $this->template->products = WDB\Wrapper\TableFactory::fromName('products')
                ->getDatasource()
                ->filter(array('category'=>$productCategory))
                ->appendOrder(new WDB\Query\Element\OrderRule(WDB\Query\Element\ColumnIdentifier::create('shift'), \WDB\Query\Element\OrderRule::DESC))
                ->run();
        $this->template->categoryName = 
                WDB\Wrapper\TableFactory::fromName('product_categories')
                ->getDatasource()
                ->select('name')
                ->filter(array('ident'=>$productCategory))
                ->run()
                ->singleValue();
    }

}
